package day14_junit_reflect_annotation_proxy.com.itheima.d2_reflect;

import org.junit.Test;

import java.lang.reflect.Constructor;

public class Test2_Constructor {
    @Test
    public void testGetConstructors(){
        Class<Cat> c = Cat.class;
        Constructor<?>[] constructors = c.getDeclaredConstructors();
        for (Constructor<?> con : constructors) {
            System.out.println(con.getName() + "-->" + con.getParameterCount());
        }

    }
    @Test
    public void testGetConstructor() throws Exception{
        Class<Cat> c = Cat.class;
        Constructor<Cat> con1 = c.getDeclaredConstructor();
        Constructor<Cat> con2 = c.getDeclaredConstructor(String.class, int.class);
        Cat c1 = (Cat) con1.newInstance();
        System.out.println(c1);

        con2.setAccessible( true);
        Cat c2 = con2.newInstance("加菲", 1);
        System.out.println(c2);
    }
}
